package com.lianjia.analysis.model;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Map;

/**
 * 房屋信息实体类，对应MongoDB中的house_info集合
 */
@Document(collection = "house_info")
public class HouseInfo {
    @Id
    private String id;
    private String title;       // 标题
    private String cityName;    // 城市名称
    private String link;        // 详情链接
    private String image;       // 图片URL
    private String location;    // 位置信息，包含小区名和区域
    private String district;    // 区域，从location中提取
    private String community;   // 小区，从location中提取
    private Price price;        // 价格信息
    private Map<String, String> details;  // 详细信息（户型、面积、朝向等）
    private Long createTime;    // 创建时间
    private Long updateTime;    // 更新时间

    /**
     * 价格信息内部类
     */
    public static class Price {
        private Double totalPrice;    // 总价（数值）
        private String totalPriceText; // 总价（文本）
        private Double unitPrice;     // 单价（数值）
        private String unitPriceText;  // 单价（文本）
        
        public Double getTotalPrice() {
            return totalPrice;
        }
        
        public void setTotalPrice(Double totalPrice) {
            this.totalPrice = totalPrice;
        }
        
        public String getTotalPriceText() {
            return totalPriceText;
        }
        
        public void setTotalPriceText(String totalPriceText) {
            this.totalPriceText = totalPriceText;
        }
        
        public Double getUnitPrice() {
            return unitPrice;
        }
        
        public void setUnitPrice(Double unitPrice) {
            this.unitPrice = unitPrice;
        }
        
        public String getUnitPriceText() {
            return unitPriceText;
        }
        
        public void setUnitPriceText(String unitPriceText) {
            this.unitPriceText = unitPriceText;
        }
    }

    // 获取户型（从details中提取）
    public String getLayout() {
        return details != null ? details.get("configuration") : null;
    }

    // 获取面积值（从details中提取）
    public Double getArea() {
        if (details != null && details.containsKey("areaValue")) {
            try {
                return Double.parseDouble(details.get("areaValue"));
            } catch (NumberFormatException e) {
                return null;
            }
        }
        return null;
    }

    // 获取面积值（从details中提取），与getArea方法功能相同
    public Double getAreaValue() {
        return getArea();
    }

    // 获取面积文本（从details中提取）
    public String getAreaText() {
        return details != null ? details.get("area") : null;
    }

    // 获取朝向（从details中提取）
    public String getOrientation() {
        return details != null ? details.get("towards") : null;
    }

    // 获取装修情况（从details中提取）
    public String getDecoration() {
        return details != null ? details.get("decorate") : null;
    }

    // 获取楼层（从details中提取）
    public String getFloor() {
        return details != null ? details.get("storey") : null;
    }

    // 获取建筑年代（从details中提取）
    public String getBuildYear() {
        return details != null ? details.get("buildYear") : null;
    }

    // 获取建筑类型（从details中提取）
    public String getBuildType() {
        return details != null ? details.get("categorie") : null;
    }

    // 获取单价（从price中提取）
    public Double getUnitPrice() {
        return price != null ? price.getUnitPrice() : null;
    }

    // 获取总价（从price中提取）
    public Double getTotalPrice() {
        return price != null ? price.getTotalPrice() : null;
    }

    // Getter和Setter方法
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
        
        // 从location中提取district和community
        if (location != null && location.contains(",")) {
            String[] parts = location.split(",");
            if (parts.length >= 2) {
                this.community = parts[0].trim();
                this.district = parts[1].trim();
            }
        }
    }

    public String getDistrict() {
        return district;
    }

    public void setDistrict(String district) {
        this.district = district;
    }

    public String getCommunity() {
        return community;
    }

    public void setCommunity(String community) {
        this.community = community;
    }

    public Price getPrice() {
        return price;
    }

    public void setPrice(Price price) {
        this.price = price;
    }

    public Map<String, String> getDetails() {
        return details;
    }

    public void setDetails(Map<String, String> details) {
        this.details = details;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    public Long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Long updateTime) {
        this.updateTime = updateTime;
    }
} 